{% extends 'TopxiaAdminBundle::layout.html.twig' %}
{% import "TopxiaAdminBundle::macro.html.twig" as web_macro %}
{% set menu = 'admin_operation_invite_coupon' %}

{% set script_controller = 'invite/coupon.js' %}

{% block main %}
    {% include 'TopxiaAdminBundle:Invite:tab-data.html.twig' %}

  {% if filter == 'invited' %}
    {% set actionUrl = path('admin_invite_coupon', {filter: filter}) %}
	{% elseif filter == 'invite' %}
		{% set actionUrl = path('admin_invite_coupon_query') %}
	{% endif %}

	<form  class="form-inline well well-sm" action="{{ actionUrl }}" method="get" novalidate>
    <input class="form-control" type="text" name="nickname" placeholder="用户名" value="{{ app.request.query.get('nickname')}}">
     <div class="form-group">
    领取时间:
    <input class="form-control" type="text" id="start-date" name="startDateTime" placeholder="开始时间" value="{{ app.request.get('startDateTime') }}">
    <div class="form-group">-</div>
    <input class="form-control" type="text" id="end-date" name="endDateTime" placeholder="结束时间" value="{{ app.request.get('endDateTime') }}">
    </div>
    <button class="btn btn-primary" type="submit">搜索</button>
	</form>

  <table class="table table-hover table-striped" >
		<thead>
			<tr>
				<th width="15%">用户名</th>
				<th width="10%">领取时间</th>
				<th width="15%">面值</th>
				<th width="20%">使用情况</th>
				<th width="15%">使用时间</th>
				<th width="25%">订单信息</th>
			</tr>
		</thead>
		<tbody>
		{% for cardInformation in cardInformations %}
			{% if filter == 'invite' %}
				{% set user = users[cardInformation.inviteUserId]|default(null) %}
				{% set card = cards[cardInformation.inviteUserCardId]|default(null) %}
				{% set coupon = coupons[cardInformation.inviteUserCardId]|default(null) %}
				{% set order = orders[coupon.orderId]|default(null) %}
			{% elseif filter == 'invited' %}
				{% set user = users[cardInformation.invitedUserId]|default(null) %}
				{% set card = cards[cardInformation.invitedUserCardId]|default(null) %}
				{% set coupon = coupons[cardInformation.invitedUserCardId]|default(null) %}
				{% set order = orders[coupon.orderId]|default(null) %}
			{% endif %}									  
			<tr>
				<td>{% if user %}{{ web_macro.user_link(user) }}{% else %}-{% endif %}</td>
				<td>{{ card.createdTime|date('Y-m-d H:i:s')}}</td>
				<td>{{coupon.rate}}元</td>
				<td>
					{% if card.status == 'unused' %}
						未使用
					{% elseif card.status == "receive" %}
						已领取
					{% elseif card.status == "used" %}
						已使用
					{% endif %}
				</td>
				<td>
					{% if card.useTime != 0 %}
      			{{ card.useTime|date('Y-m-d H:i:s') }}
    			{% else %}
     				 -
    			{% endif %}
    		</td>
				<td class="text-danger">{{ order.title|default('-') }}</td>					
			</tr>
		{% else %}
			<tr><td colspan="20"><div class="empty">暂无页面记录</div></td></tr>
		{% endfor %}
		</tbody>
	</table>

{{ web_macro.paginator(paginator) }}
{% endblock %}